<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<div class="bjui-pageContent">
    <form id="addRoleForm" class="pageForm">
        <div style="padding-left:50px" class="pageFormContent" data-layout-h="0">
        	<div style="height:80px;">&nbsp;</div>
        	
            <label for="role.name" class="control-label x90">角色名称：</label>
            <input type="text" name="name" id="role_name" value="" />
        </div>
        <div class="bjui-footBar">
            <ul>
                <li><button type="button" class="btn-close">关闭</button></li>
                <li><button type="submit" class="btn-default">保存</button></li>
            </ul>
        </div>
    </form>
</div>

<script type="text/javascript">
(function($){
	//创建包名
	CH.package("com.ch.controller");
	CH.package("com.ch.view");
	
	//创建视图层类
	com.ch.view.AddRoleView = CH.create({
		construct : function( controller ) {
			this.controller = controller;
		},
		
		getValues : function() {
			var data = {};
			data.name = $('#role_name').val();
			return data;
		}
	});
	
	//创建控制器类
	com.ch.controller.AddRoleController = CH.create({
		construct : function() {
			this.view = new com.ch.view.AddRoleView(this);
		},
		
		create : function() {
			var url = '/webapi/role';
			var data = this.view.getValues();
			
			CH.PostRequest(url, data, this.createHandle, this);
		},
		
		createHandle : function(result) {
			if(result.code == SUCCESS) {
				CH.utils.showMessageOK("保存成功!");
			}
			else {
				CH.common.showError(result.code);
			}
		}
	});
	
	$(document).ready(function() {
		var controller = new com.ch.controller.AddRoleController();
		
		$('#addRoleForm').validator({ 
	        theme: 'yellow_right_effect',
	        focusCleanup: true,
	        stopOnError:true,
	        timely: 2,
	        fields: {
	            "name": {
	                rule: "required",
	                msg: {required: "角色名称必须填写!"}
	            }
	        },
	        //验证成功
	        valid: function(form) {
	        	controller.create();
	        }
	    });
	});
	
})(jQuery);



</script>